// 调用数据库
const connection = require("../data/lcs_resumedata");

// 前端展示页面
module.exports.dynamic = (req,res)=>{
    res.render('lcs_dynamic');
}

// 展示最开始页面
module.exports.resume = (req, res) => {
    
    connection.query('select count(*) as strip from lss',(error,result)=>{
        if (error) {
            console.log(error);
        } else {
            res.render('lcs_resume',result[0]);
        }
    })
}

// 展示入档页面
module.exports.rudang = (req, res) => {
    connection.query('select count(*) as strip from lss where status="入档"',(error,result)=>{
        if (error) {
            console.log(error);
        } else {
            res.render('lcs_rudang',result[0]);
        }
    })
}

// 展示面试页面
module.exports.mianshi = (req, res) => {
    connection.query('select count(*) as strip from lss where status="通知面试"',(error,result)=>{
        if (error) {
            console.log(error);
        } else {
            res.render('lcs_mianshi',result[0]);
        }
    })
}


// 展示录用页面
module.exports.luyong = (req, res) => {
    connection.query('select count(*) as strip from lss where status="录用"',(error,result)=>{
        if (error) {
            console.log(error);
        } else {
            res.render('lcs_luyong',result[0]);
        }
    })
}


// 展示不录用页面
module.exports.noluyong = (req, res) => {
    connection.query('select count(*) as strip from lss where status="不录用"',(error,result)=>{
        if (error) {
            console.log(error);
        } else {
            res.render('lcs_noluyong',result[0]);
        }
    })
}


// 展示违约页面
module.exports.weiyue = (req, res) => {
    connection.query('select count(*) as strip from lss where status="违约  "',(error,result)=>{
        if (error) {
            console.log(error);
        } else {
            res.render('lcs_weiyue',result[0]);
        }
    })
}





// 查询全部简历所有数据
module.exports.resumeshow = (req, res) => {
    connection.query('select*from lss', (error, result) => {
        if (error) {
            console.log(error);
        } else {
            res.json(result);
        }
    })
}

// 查询入档所有数据
module.exports.rudangshow = (req, res) => {
    connection.query('select*from lss where status="入档"', (error, result) => {
        if (error) {
            console.log(error);
        } else {
            res.json(result);
        }
    })
}


// 查询面试所有数据
module.exports.mianshishow = (req, res) => {
    connection.query('select*from lss where status="通知面试"', (error, result) => {
        if (error) {
            console.log(error);
        } else {
            res.json(result);
        }
    })
}


// 查询录用所有数据
module.exports.luyongshow = (req, res) => {
    connection.query('select*from lss where status="录用"', (error, result) => {
        if (error) {
            console.log(error);
        } else {
            res.json(result);
        }
    })
}


// 查询不录用所有数据
module.exports.noluyongshow = (req, res) => {
    connection.query('select*from lss where status="不录用"', (error, result) => {
        if (error) {
            console.log(error);
        } else {
            res.json(result);
        }
    })
}


// 查询违约所有数据
module.exports.weiyueshow = (req, res) => {
    connection.query('select*from lss where status="违约"', (error, result) => {
        if (error) {
            console.log(error);
        } else {
            res.json(result);
        }
    })
}


// 新建简历
// 展示添加数据页面
module.exports.resumeadd = (req, res) => {
    res.render('lcs_resumeadd');
}


// 添加数据
module.exports.resumeadds = (req, res) => {
    let emp = [req.body.job, req.body.name, req.body.phone, req.body.sex, req.body.birth, req.body.education, req.body.working, req.body.remarks, req.body.resume, req.body.status];
    connection.query("insert into lss(job,name,phone,sex,birth,education,working,remarks,resume,status) values(?,?,?,?,?,?,?,?,?,?)", emp, (error, result) => {
        if (error) {
            console.log(error);
        } else {
            res.json({
                code: 0,
                msg: '添加成功'
            })
        }
    })
}


// 删除用户
module.exports.resumedelete = (req, res) => {
    connection.query('delete from lss where id=' + req.query.id, (error, result) => {
        if (error) {
            console.log(error);
        } else {
            res.json({
                code: 1,
                msg: '删除成功'
            })
        }
    })
}


// 显示编辑页面
module.exports.resumemodify = (req, res) => {
    // console.log(req.query.id);
    connection.query('select * from lss where id =?', req.query.id, (error, result) => {
        if (error) {
            console.log(error);
        } else {
            res.render('lcs_resumemodify', result[0]);
        }
    })
}


// 更新数据
module.exports.resumeupdate = (req, res) => {
    let params = [req.body.job, req.body.name, req.body.phone, req.body.sex, req.body.birth, req.body.education, req.body.working, req.body.remarks, req.body.resume, req.body.status, req.body.id];
    connection.query('update lss set job=?,name=?,phone=?,sex=?,birth=?,education=? ,working=?,remarks=?,resume=?,status=? where id=?', params, (error, result) => {
        if (error) {
            console.log(error);
        } else {
            res.json({
                code: 2,
                msg: '更新成功'
            })
        }
    })
}


// 搜索用户
module.exports.resumecerh = (req, res) => {
    connection.query('select *from lss where name like "%' + req.body.emp + '%"', (error, result) => {
        if (error) {
            console.log(error);
        } else {
            res.json(result);
        }
    })
}

// 几条数据
module.exports.resumepo = (req,res)=>{
    connection.query('select count(*) as strip from lss where name like "%' + req.body.emp + '%"', (error, result) => {
        if (error) {
            console.log(error);
        } else {
            res.json(result[0]);
        }
    })
}

// 显示查看页面  显示的同时让它回显数据
module.exports.chaxun = (req, res) => {
    // 回显 
    connection.query('select*from lss where id=?', req.query.id, (error, result) => {
        if (error) {
            console.log(error);
        } else {
            res.render('lcs_chaxun', result[0]);
        }
    })
}
